<?php

namespace App\Models;

class SettlementModel
{
    /**
     * 查询结算信息
     * entry conn
     * return int
     * */
    public static function getSettlement($conn,$id){
        $querySql="select `id`,`uid`,`money`,`no` from `settlement` where `id` =$id";
        return $conn->readConn($querySql);
    }
    public static function getSettlementAll($conn,$uid){
        $querySql="select `id`,`uid`,`money`,`no`,`total`,`cost`,`time` from `settlement` where `uid` =$uid and `state` =2 order by id asc";
        return $conn->readConn($querySql,true);
    }
    /**
     * 插入用户付款信息
     * entry conn,$SettlementExample
     * return int
     * */
    public static function insertSettlementInside($conn,$SettlementExample){
        $insertSql = "insert into `settlement`(`uid`,`money`,`no`,`type`,`total`,`cost`) values ($SettlementExample->uid,$SettlementExample->money,'$SettlementExample->no',$SettlementExample->type,$SettlementExample->total,$SettlementExample->cost)";
        return $conn->executeConn($insertSql);
    }

    /**
     * 修改付款信息加字段
     * entry UsersCollExample
     * return int
     * */
    public static function editInside($conn,$Example){
        $joinSql="";
        if($Example->state !=null){
            $joinSql.=" `state` = '$Example->state',";
        }
        if($Example->endtime !=null){
            $joinSql.=" `endtime` = '$Example->endtime',";
        }
        if($Example->total !=null){
            $joinSql.=" `total` = '$Example->total',";
        }
        if($Example->cost !=null){
            $joinSql.=" `cost` = '$Example->cost',";
        }
        if($joinSql !=null){
            $innerJoin = rtrim($joinSql,",");
            $upUserSql="UPDATE  `settlement` SET $innerJoin WHERE `id` = '$Example->id'";
            return $conn->executeConn($upUserSql);
        }
    }
}